<?php
namespace app\shop\controller;
use think\Controller;
use think\Db;

class Common extends Controller{
    public $webconfig;
    
    Public function _initialize(){
        if(!session('shopadmin_id') || !session('shopsh_id')){
            $this->redirect('login/index');
        }
        
        $this->_getconfig();

        // 微信小程序支付配置
        $wxpayRes=db('wxpay_config')->where('id',1)->find();
        $this->wechatPayConfig = [
            // 前面的appid什么的也得保留哦
            'app_id'             => $wxpayRes['appid'],
            'mch_id'             => $wxpayRes['mch_id'],
            'key'                => $wxpayRes['api_key'],
            'cert_path'          => '/www/wwwroot/demo.wo-shop.net/cert/apiclient_cert.pem', // 绝对路径！！！！
            'key_path'           => '/www/wwwroot/demo.wo-shop.net/cert/apiclient_key.pem',      // 绝对路径！！！！
            //'notify_url'         => $configres['weburl'].'/api/Wxpay/wxNotify',     // 你也可以在下单时单独设置来想覆盖它
        ];
    }
    
    public function _getconfig(){
        $_configres = Db::name('config')->where('ca_id','in','1,2,4,5,10,15,17')->field('ename,value')->select();
        $configres = array();
        foreach ($_configres as $v){
            $configres[$v['ename']] = $v['value'];
        }
        $this->webconfig=$configres;
        $this->assign('configres',$configres);
    }
    
}